package mobi.hami.huapin.util;

import mobi.hami.huapin.model.base.PageQO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 *  查询条件 帮助类
 *
 * @author 阿飞 jijunjian@hami.mobi
 * @date 2018/8/24 17:41
 */
public class SearchListUtil {

    private static Logger logger = LoggerFactory.getLogger(SearchListUtil.class);

    /**
     * 根据条件返回 基本的搜索条件，pagesize,pageindex, orderby
     * @param reqMap
     * @return
     */
    public  static PageQO<?>  resolveSearchData(Map<String,Object> reqMap)
    {
        PageQO<?> pageQO = new PageQO<>();
        String orderName = "id";
        if (reqMap.containsKey("order_name") && reqMap.get("order_name").toString().length() > 0)
        {
            orderName = reqMap.get("order_name").toString();
        }

        String orderType = "asc";
        if (reqMap.containsKey("order_type") && reqMap.get("order_type").toString().length() > 0)
        {
            orderType = reqMap.get("order_type").toString();
        }

        int pageindex = 1;
        if (reqMap.containsKey("pageindex")) {
            pageindex = Integer.parseInt(reqMap.get("pageindex").toString());
        }

        int pagesize = 10;
        if (reqMap.containsKey("pagesize")) {
            pagesize = Integer.parseInt(reqMap.get("pagesize").toString());
        }

        pageQO.setPageNum(pageindex);
        pageQO.setPageSize(pagesize);
        pageQO.setOrderBy(orderName+" "+orderType);


        return  pageQO;
    }
}
